
function isAndroid() {
	var userAgent = navigator.userAgent || navigator.vendor || window.opera;

	if (/android/i.test(userAgent)) {
		return true;
	}
	return false;
}

function fetchHotpointSummary(options = {}) {
	
	XT.jsonp({
		url:'/account/mywallet-info',
		data: {uid:XT.search.userId},
		super_success: function(res){
			// console.log('/account/account-by-id=====', res);
			options.callback && options.callback(res || []);
		}
	})
}

var store = new Vuex.Store({
	state: {
		showLoading: true,
		hotPointSummary: {}
	},
	actions: {
		getHotpointSummary({commit, state}, payload = {}){
			console.log(333)
			commit('HIDE_LOADING');
			fetchHotpointSummary({
				callback: function(res) {
					commit('HIDE_LOADING');
					if(res.code == 'ok') {
						commit('HOT_POINT_SUMMARY', {hotPointSummary: res.data})
					}
				}
			})
		},
	},
	mutations: {
		HOT_POINT_SUMMARY(state, payload = {}) {
			console.log(payload)
			state.hotPointSummary = payload.hotPointSummary;
		},
		HIDE_LOADING(state, payload = {}) {
			state.showLoading = false;
		}
	}
});

window.App = new Vue({
	el: '#App',
	store: store,
	data: {

	},
	methods: {
		openWx: function() {
			var that = this;
			that.openWxDialog()
			XT.bridge.call('copyToClipboard',{content: encodeURIComponent('百媚直播服务号')},function (res) {
				if(isAndroid()) {
					setTimeout(function(){
						that.openWxDialog()
					}, 2000)
				}else {
					that.openWxDialog()
				}
			});
		},
		openWxDialog: function() {
			MINT.MessageBox({
				title: '提示',
				message: '点击微信右上角+号,"添加朋友"粘贴并搜索,即可关注',
				showCancelButton: true,
				confirmButtonText: '前往微信',
				closeOnClickModal: true
			}).then(action => {
				if(action == 'confirm') {
					window.location.href = 'bmlive://bmlive/openWX';
				}
			})
		},
		callCustomerService: function() {
			window.location.href = 'bmlive://bmlive/callCustomerService';
		}
	},
	computed: {
		showLoading: function() {
			return this.$store.state.showLoading;
		},
		hotPointSummary: function() {
			return this.$store.state.hotPointSummary;
		}
	},
	created: function() {
		var that = this;
		XT.getUserInfo(function(info){
			that.$store.dispatch('getHotpointSummary');
		});
	},
});

